package com.plugin.seed.mybatis.defaultvalue.interceptor;

import com.plugin.seed.mybatis.defaultvalue.util.DefaultValueUtil;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;

/**
 * @author Peter Fan
 */
@Intercepts({
        @Signature(
                type = Executor.class,
                method = "update",
                args = {MappedStatement.class, Object.class})
})
public class ColumnDefaultValueUpdateInterceptor implements Interceptor {

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        Object parameter = invocation.getArgs()[1];
        DefaultValueUtil.initDefaultValue(parameter);
        return invocation.proceed();
    }

}

